import JSEncrypt from 'jsencrypt';
import request from '../utils/request';
import { ipConfig } from './config';
import { Constants } from '../utils';

const PATH = '/api-ms/system/userSecurityInfo';


// http://mesdev.chalco-steering.com:1708/appgateway/api-ms/system/userSecurityInfo/modifyPassword
// newPassword
// oldPassword
// userId

export const modifyPassword = async params => {
  const encrypt = new JSEncrypt();
  encrypt.setPublicKey(Constants.RSA_PUBLICKEY);
  const newPassword = encrypt.encrypt(params.newPassword);
  const oldPassword = encrypt.encrypt(params.oldPassword);
  const newParams = { ...params, newPassword, oldPassword };
  return request(`${ipConfig.url(PATH)}/modifyPassword`, {
    method: 'POST',
    body: newParams,
  }).then(resultMsg);
};

const resultMsg = response => response.resultMsg;
